package com.swanclouds.redfish.systems;

import com.swanclouds.api.systems.PCIeFunctionService;
import com.swanclouds.api.systems.SystemService;
import com.swanclouds.core.transport.ClientConstants;
import com.swanclouds.model.common.redfish.CollectionResource;
import com.swanclouds.model.systems.PCIeFunctions;
import com.swanclouds.redfish.internal.BaseSystemService;
import com.swanclouds.redfish.systems.domain.PCIeFunctionsModel;
import com.swanclouds.redfish.systems.domain.Systems;

import java.util.ArrayList;
import java.util.List;

/**
 *  * Description:
 *  * Author:      zhangliqiang@asiacom.net.cn
 *  * Date:        2022-07-16 11:31.
 *  
 */
public class PCIeFunctionsServiceImpl extends BaseSystemService implements PCIeFunctionService {

    private SystemService systemService = new SystemServiceImpl();

    /**
     * 查询服务器指定PCIe设备归属资源集合信息
     * @param  pciedevicesId PCIe设备Id
     * @return  CollectionResource
     **/
    @Override
    public CollectionResource get(String pciedevicesId) {
        return get(CollectionResource.class, uri(ClientConstants.PATH_CHASSIS_PCIEDEVICES_ID_FUNCTIONS,getSystemId(),pciedevicesId)).execute();
    }

    @Override
    public PCIeFunctions getFunctionsId(String pciedevicesId, String functionsId) {
        return get(PCIeFunctionsModel.class, uri(ClientConstants.PATH_CHASSIS_PCIEDEVICES_ID_FUNCTIONS_ID,getSystemId(),pciedevicesId,functionsId)).execute();
    }

    @Override
    public List<PCIeFunctionsModel> list() {
        List<PCIeFunctionsModel> pcIeFunctionsModels = new ArrayList<PCIeFunctionsModel>();
        Systems systems = systemService.get();
        systems.getPCIeFunctions().stream().forEach(ref ->{
            pcIeFunctionsModels.add(get(PCIeFunctionsModel.class, uri(ref)).execute());
        });
        return pcIeFunctionsModels;
    }

}
